package practice.jackson;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import practice.jackson.bean.User;

import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        ObjectMapper objectMapper = new ObjectMapper();
        String json =  "{\"username\":\"Mahesh\", \"password\":21}";
        User user = objectMapper.readValue(json, User.class);
        System.out.println(objectMapper.writeValueAsString(user));
        System.out.println(user.toString());


        JsonFactory jsonFactory = new JsonFactory();
        JsonParser jsonParser = jsonFactory.createParser(json);
        System.out.println(jsonParser.getValueAsString("username"));
    }
}
